import { mul, div } from '@/lib/util'
import { Btn } from '@/types'

export function getPxPerSec(scale: number): number {
  return mul(0.015, Math.pow(scale, div(scale, 140)))
}
export function getTimeInterval(scale: number): number {
  const intervals = [
    1,
    2,
    3,
    5,
    10,
    20,
    30,
    60,
    2 * 60,
    3 * 60,
    5 * 60,
    10 * 60,
    20 * 60,
    30 * 60,
    60 * 60,
    2 * 60 * 60,
    3 * 60 * 60,
    5 * 60 * 60,
    10 * 60 * 60,
    20 * 60 * 60,
    30 * 60 * 60,
  ]
  const minDisplayLength = 60
  let interval = 3600
  const pxPerSec = getPxPerSec(scale)
  for (const item of intervals) {
    if (pxPerSec * item >= minDisplayLength) {
      interval = item
      break
    }
  }
  return interval
}

export function getAction(from: Btn): string {
  return from.id
}
